home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cgazv5n5.arc
/
LIST6.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-23
|
1KB
|
46 lines
/*---------------------------------------- Listing 6 ------
* An intelligent control-break handler.
* See Listing 1 for copyright terms.
*-------------------------------------------------------*/
#include <stdio.h>
#include <signal.h>
void CtlBrkHandler ( int Signal, int SubCode );
void main ( void );
void CtlBrkHandler ( int Signal, int SubCode )
{
/*---------------------------------------------------------
* Without the following line, Control-Break would by now
* be reset to default, and the program would quit.
*-------------------------------------------------------*/
signal ( SIGINT, SIG_IGN );
printf( "Signal %d, SubCode %d was raised\n",
Signal, SubCode);
/*---------------------------------------------------------
* The following Control-Break (explicitly raised)
* will be ignored!
*-------------------------------------------------------*/
raise ( SIGINT );
/*---------------------------------------------------------
* Leaving the handler, we can reactivate Control-Break
* for future use.
*-------------------------------------------------------*/
signal ( SIGINT, CtlBrkHandler );
}
void main ( void )
{
void (*OldHandler) ( int Signal );
OldHandler = signal ( SIGINT, CtlBrkHandler );
if ( OldHandler == SIG_ERR )
printf ( "signal failed\n" );
raise ( SIGINT );
}